<template>
  <div class="content">
    <!-- 训练中心- 专项训练 -->
    <div class="special">
      <div class="left">
        <div class="bg">
          <p class="size">{{ zhuan }}</p>
          <p class="qiang">
            <span>{{ qiang }}</span>
            <span>{{ zi }}</span>
          </p>
        </div>
        <form>
          <div>
            <p>{{ kemu }}</p>
            <select v-model="subjects">
              <option value="请选择科目">请选择科目</option>
              <option value="UI">UI</option>
              <option value="前端">前端</option>
              <option value="PHP">PHP</option>
              <option value="JAVA">JAVA</option>
            </select>
          </div>
          <div>
            <p>{{ ti }}</p>
            <select v-model="topic">
              <option value="请选择">请选择</option>
              <option value="选择题">选择题</option>
              <option value="判断题">判断题</option>
              <option value="填空题">填空题</option>
              <option value="简答题">简答题</option>
            </select>
          </div>
          <div>
            <p>{{ shu }}</p>
            <input type="number" max="10" min="1" name="" placeholder="填写试卷数量" />
          </div>
          <div>
            <p>{{ ming }}</p>
            <input type="text" name="" placeholder="填写试卷名称" />
          </div>
          <div>
            <p>{{ shi }}</p>
            <select v-model="time">
              <option value="请选择时间">请选择时间</option>
              <option value="60分钟">60分钟</option>
              <option value="90分钟">90分钟</option>
              <option value="120分钟">120分钟</option>
            </select>
          </div>
          <button type="button">开始组卷</button>
        </form>
      </div>
      <div class="right">
        <div class="title">
          <p v-for="(item, index) in tit" :key="index">{{ item.name }}</p>
        </div>
        <div class="list" v-for="(item, index) in list" :key="index" :data="tableData">
          <div class="con">
            <p class="grey">{{ item.name }}</p>
            <p class="grey">{{ item.time }}</p>
            <router-link to="/test">
              <button>开始答题</button>
            </router-link>
          </div>
        </div>
        <!-- <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage2"
            :page-sizes="[100, 200, 300, 400]"
            :page-size="100"
            layout="sizes, prev, pager, next"
            :total="1000"
          >
          </el-pagination>
        </div> -->
        <el-col :span="24" class="toolbar pageBar">
          <el-pagination
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            layout=" prev, pager, next,total,jumper"
            :total="total"
            background
          >
          </el-pagination>
        </el-col>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import { Table, TableColumn, Pagination } from "element-ui";
import VueResource from "vue-resource";
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Pagination);
Vue.use(VueResource);
export default {
  data() {
    return {
      currentPage2: 5,
      subjects: "请选择科目",
      topic: "请选择",
      time: "请选择时间",
      zhuan: "专项训练",
      kemu: "请选择科目",
      qiang: "强化练习",
      zi: "自主学习",
      ti: "请设置题型",
      shu: "请填写试题数量",
      ming: "请填写试题名称",
      shi: "答题时间",
      tit: [{ name: "试卷名称" }, { name: "创建时间" }, { name: "操作" }],
      list: [
        { name: "Java基础练习", time: "2021-04-12 09: 10: 19" },
        { name: "Java基础练习", time: "2021-04-12 09: 10: 19" },
      ],
      
      
      tableData: [],
      currentPage: 1, //当前页
      total: 2, //数据总条数
      pageSize: 10, //每页显示的数据条数
    }
  },
  mounted() {
    // chrome
    document.body.scrollTop = 0;
    // firefox
    document.documentElement.scrollTop = 0;
    // safari
    window.pageYOffset = 0;
  },
  // methods: {
  //   handleSizeChange() {
  //     // console.log(`每页 ${val} 条`);
  //   },
  //   handleCurrentChange() {
  //     // console.log(`当前页: ${val}`);
  //   },
  // },
  methods: {
    //该方法用来从后台拉取数据，以get方式请求
    //例如：默认每页显示10条数据，当用户点击页码1时，向后端请求第0~9条数据
    getData() {
      var start = (this.currentPage - 1) * this.pageSize; //请求的数据从第start条开始
      var end = this.currentPage * this.pageSize - 1; //到第end条结束
      this.$http.get("/api/v1/get_data/?start=" + start + "&end=" + end).then(
        function (response) {
          this.tableData = response.body.logs;
        },
        function () {
          // console.log(err);
        }
      );
    },
    //该方法当用户点击页码改变时触发，val为切换到的页码，页码变化后向后台请求新的数据
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
  },
  //该方法为组件创建前的钩子函数，主要用来初始化表格，当表格被加载出来即向后台先请求前10条数据
  beforeCreate: function () {
    this.$http.get("/api/v1/get_data/?start=0&end=10").then(
      function (response) {
        this.total = response.body.log_total;
        this.tableData = response.body.logs;
      },
      function () {
        // console.log(err);
      }
    );
  },
}
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  font-size: 16px;

  .special {
    width: 65%;
    margin: 0 auto;
    // min-width: 1066px;
    margin-top: 2rem;
    justify-content: space-between;
    display: flex;

    .left {
      width: 22%;
      padding: 2rem 2%;
      box-shadow: 0px 5px 20px 0px rgba(116, 116, 116, 0.35);
      border-radius: 10px;

      .bg {
        width: 100%;
        background: url("../../assets/1(1).png") no-repeat center center;
        background-size: 100% 100%;
        color: #fff;
        padding-top: 1.4rem;
        text-indent: 1em;

        .size {
          font-size: 20px;
          margin: 0.6rem 0;
        }

        .qiang {
          padding-bottom: 2.8rem;
        }
      }

      form {
        color: #747474;
        p {
          margin: 0;
        }

        > div {
          margin-top: 1.2rem;

          select {
            width: 100%;
            height: 30px;
            line-height: 30px;
            border: 2px solid #e9e9e9;
            margin-top: 0.4rem;
            outline: none;
            color: #666666;

            option {
              width: 100%;
            }
          }

          input {
            width: 97%;
            height: 24px;
            line-height: 24px;
            border: 2px solid #e9e9e9;
            margin-top: 0.4rem;
            outline: none;
            color: #666666;
          }
        }

        button {
          width: 100%;
          color: #fff;
          height: 40px;
          background: #0096f6;
          border-radius: 5px;
          border: 1px solid #0096f6;
          outline: none;
          margin-top: 1.6rem;
        }
      }
    }

    .right {
      width: 66%;
      padding: 2rem 2%;
      box-shadow: 0px 5px 20px 0px rgba(116, 116, 116, 0.35);
      border-radius: 10px;

      .title {
        width: 100%;
        justify-content: space-between;
        display: flex;
        border-bottom: 1px solid #c7c7c7;
        padding-bottom: 0.8rem;

        p {
          width: 80%;
          margin: 0 auto;
          color: #0096f6;
        }
      }

      .list {
        width: 100%;
        padding: 0.2rem 0;
        border-bottom: 1px solid #c7c7c7;

        .con {
          width: 74%;
          justify-content: space-between;
          display: flex;
          align-items: center;
          padding: 7px 0;
          .grey {
            color: #999999;
          }

          button {
            background: #0096f6;
            color: #fff;
            padding: 8px;
            // line-height: 30px;
            // height: 30px;
            border: 1px solid #0096f6;
            outline: none;
          }
        }
      }

      /deep/ .el-pagination {
        text-align: center;
        margin-top: 1rem;
      }

      // .block {
      //   text-align: center;
      //   margin-top: 3rem;
      // }
    }
  }
}
</style>